home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 8 / Revista do CD-ROM 8.iso / dados / program / skyborg / skyborg.exe / SHARED.DXR / 01005_Object Utilities.ls < prev    next >
Encoding:
Text File  |  1995-07-24  |  15.0 KB  |  509 lines

  1. on ChangeState whichObject
  2.   global gObjStateList
  3.   set thisObj to getaProp(gObjStateList, whichObject)
  4.   set myStateCount to item 2 of thisObj
  5.   set newState to item 1 of thisObj + 1
  6.   if newState > myStateCount then
  7.     set newState to 1
  8.   end if
  9.   put integer(newState) into item 1 of thisObj
  10.   setaProp(gObjStateList, whichObject, thisObj)
  11. end
  12.  
  13. on ReverseState whichObject
  14.   global gObjStateList
  15.   set thisObj to getaProp(gObjStateList, whichObject)
  16.   set myStateCount to item 2 of thisObj
  17.   set newState to item 1 of thisObj - 1
  18.   if newState < 1 then
  19.     set newState to myStateCount
  20.   end if
  21.   put integer(newState) into item 1 of thisObj
  22.   setaProp(gObjStateList, whichObject, thisObj)
  23. end
  24.  
  25. on SetState whichObject, newState
  26.   global gObjStateList
  27.   set thisObj to getaProp(gObjStateList, whichObject)
  28.   put integer(newState) into item 1 of thisObj
  29.   setaProp(gObjStateList, whichObject, thisObj)
  30. end
  31.  
  32. on TestObjStates whichObject, whichCond
  33.   global gObjStateList
  34.   set thisObj to getaProp(gObjStateList, whichObject)
  35.   set me to 0
  36.   if voidp(thisObj) then
  37.     beep()
  38.     beep()
  39.     beep()
  40.     put whichObject, whichCond
  41.   else
  42.     if item 1 of thisObj = whichCond then
  43.       set me to 1
  44.     end if
  45.   end if
  46.   return me
  47. end
  48.  
  49. on CheckState whichObject
  50.   global gObjStateList
  51.   set thisObj to getaProp(gObjStateList, whichObject)
  52.   if voidp(thisObj) then
  53.     beep()
  54.     beep()
  55.     beep()
  56.     put whichObject
  57.   else
  58.     set me to item 1 of thisObj
  59.   end if
  60.   return me
  61. end
  62.  
  63. on GetBaseItem whichObject
  64.   set done to 0
  65.   set the itemDelimiter to "_"
  66.   if the number of items in whichObject = 2 then
  67.     delete char -30002 of whichObject
  68.   end if
  69.   set the itemDelimiter to ","
  70.   return whichObject
  71. end
  72.  
  73. on Dash2UnderScore what
  74.   repeat with count = 1 to the number of chars in what
  75.     if char count of what = "-" then
  76.       put "_" into char count of what
  77.     end if
  78.   end repeat
  79.   return what
  80. end
  81.  
  82. on AddToInv whichItem
  83.   global cHUDSprite, gBorgInv, gTakenInv, gInvData, gInvArmState, cLayerSoundSprite, gMixSound, gLastSound, gBorgWeapons, cDragSprite, gCardName, gItemField, gItemCount
  84.   spriteBox(cDragSprite, 0, 500, 1, 501)
  85.   myPlaySound("Take Sound")
  86.   set the itemDelimiter to "\"
  87.   repeat with thisLine = 1 to the number of lines in field "Card Index"
  88.     if item 2 of line thisLine of field "Card Index" = whichItem then
  89.       set thisInfo to line thisLine of field "Card Index"
  90.       exit repeat
  91.     end if
  92.   end repeat
  93.   set invType to item 14 of thisInfo
  94.   set the itemDelimiter to ","
  95.   if invType = "W" then
  96.     if gBorgWeapons = EMPTY then
  97.       put whichItem after gBorgWeapons
  98.     else
  99.       put "," & whichItem after gBorgWeapons
  100.     end if
  101.   else
  102.     if gBorgInv = EMPTY then
  103.       put whichItem after gBorgInv
  104.     else
  105.       put "," & whichItem after gBorgInv
  106.     end if
  107.   end if
  108.   if gInvData = EMPTY then
  109.     put thisInfo after gInvData
  110.   else
  111.     put RETURN & thisInfo after gInvData
  112.   end if
  113.   if gTakenInv = EMPTY then
  114.     put whichItem after gTakenInv
  115.   else
  116.     put "," & whichItem after gTakenInv
  117.   end if
  118.   if gInvArmState = 1 then
  119.     ShowInvArm()
  120.   end if
  121. end
  122.  
  123. on RemoveInv whichItem
  124.   global gBorgInv, gTakenInv, gInvData
  125.   set thisObject to GetBaseItem(whichItem)
  126.   if the last char in thisObject <> "*" then
  127.     repeat with thisLine = 1 to the number of lines in gInvData
  128.       if item 2 of line thisLine of gInvData = whichItem then
  129.         delete line thisLine of gInvData
  130.         exit repeat
  131.       end if
  132.     end repeat
  133.     repeat with thisItem = 1 to the number of items in gBorgInv
  134.       if item thisItem of gBorgInv = whichItem then
  135.         delete item thisItem of gBorgInv
  136.         exit repeat
  137.       end if
  138.     end repeat
  139.     repeat with thisItem = 1 to the number of items in gInvData
  140.       if item thisItem of gInvData = whichItem then
  141.         delete item thisItem of gInvData
  142.         exit repeat
  143.       end if
  144.     end repeat
  145.   end if
  146. end
  147.  
  148. on CheckInInv whichItem
  149.   global gBorgInv, gTakenInv, gInvData
  150.   set inINV to 0
  151.   repeat with thisItem = 1 to the number of items in gBorgInv
  152.     if item thisItem of gBorgInv = whichItem then
  153.       set inINV to 1
  154.       exit repeat
  155.     end if
  156.   end repeat
  157.   return inINV
  158. end
  159.  
  160. on buildCastIndex
  161.   global myCast
  162.   set myCast to [:]
  163.   set done to 0
  164.   set thisCast to 0
  165.   repeat with thisCast = 1 to the number of castMembers
  166.     if the name of cast thisCast <> 0 then
  167.       set myCastName to the name of cast thisCast
  168.       addProp(myCast, myCastName, thisCast)
  169.     end if
  170.   end repeat
  171.   sort(myCast)
  172. end
  173.  
  174. on myPlaySound whichSound
  175.   global gLastSound, gMixSound, cLayerSoundSprite, cBackSoundSprite, myCast
  176.   if gMixSound then
  177.     sound stop cLayerSoundSprite
  178.     updateStage()
  179.     set thisSound to getaProp(myCast, whichSound)
  180.     if the preLoad of cast thisSound = 0 then
  181.       preLoadCast(thisSound)
  182.     end if
  183.     puppetSound(cLayerSoundSprite, thisSound)
  184.     updateStage()
  185.   else
  186.     sound stop 1
  187.     updateStage()
  188.     puppetSound(whichSound)
  189.     updateStage()
  190.     repeat while soundBusy(1)
  191.       nothing()
  192.     end repeat
  193.     if gLastSound <> EMPTY then
  194.       sound stop 1
  195.       updateStage()
  196.       puppetSound(gLastSound)
  197.     end if
  198.   end if
  199. end
  200.  
  201. on FindSprite whichObject
  202.   global cMaxRegions, cSiteFirstRegion, gCurrentSite
  203.   set myTestString to whichObject & "_" & GetBaseSite(gCurrentSite) & "_" & CheckState(whichObject)
  204.   set theSpriteReturn to 0
  205.   repeat with count = cSiteFirstRegion to cMaxRegions + cSiteFirstRegion - 1
  206.     set thisCastName to the name of cast the castNum of sprite count
  207.     set temp to offset(myTestString, thisCastName)
  208.     if temp > 0 then
  209.       set theSpriteReturn to count
  210.       exit repeat
  211.     end if
  212.   end repeat
  213.   return theSpriteReturn
  214. end
  215.  
  216. on idle
  217.   global gLastTime, gEnvDamage, gLastFire
  218.   if the timer > (gLastTime + 60) then
  219.     ProcessDamage(gEnvDamage)
  220.     set gLastTime to the timer
  221.   end if
  222.   UpdateHUDWeapon()
  223. end
  224.  
  225. on UpdatePalettes
  226.   global gPaletteList, gPalIndex, gCurrentPalette, gBrightness, gWorldPalette, gBrightAdjust, cBrightMax, cBrightMin
  227.   set PalCount to the number of items in gPaletteList
  228.   set gPalIndex to gPalIndex + 1
  229.   if gPalIndex > PalCount then
  230.     set gPalIndex to 1
  231.   end if
  232.   set thisPalette to item gPalIndex of gPaletteList
  233.   if thisPalette = "WPal" then
  234.     set thisPalette to gWorldPalette
  235.   end if
  236.   set currentBrightness to gBrightAdjust + gBrightness
  237.   if currentBrightness > cBrightMax then
  238.     set currentBrightness to cBrightMax
  239.   end if
  240.   if currentBrightness < cBrightMin then
  241.     set currentBrightness to cBrightMin
  242.   end if
  243.   put "_" & currentBrightness after thisPalette
  244.   if thisPalette <> gCurrentPalette then
  245.     puppetPalette(thisPalette, 29, 0)
  246.     set gCurrentPalette to thisPalette
  247.   end if
  248. end
  249.  
  250. on UpdateEnv
  251.   global gCurrentEnv, cBackSoundSprite, gCurrentSite, gPaletteList, gPalIndex, gCurrentPalette, gWorldPalette, cBrightMax, cBrightMin, gBrightness, gBrightAdjust, gMixSound, gLastSound, gEnvDamage, gFightMode, gWarningTime
  252.   set cEnvSite to 1
  253.   set cEnvType to 2
  254.   if (the ticks - gWarningTime) > 600 then
  255.     updateWarning("Warning-None")
  256.   end if
  257.   set envCount to the number of items in gCurrentEnv
  258.   repeat with thisEnv = 1 to envCount
  259.     if item cEnvSite of line thisEnv of gCurrentEnv = gCurrentSite then
  260.       if item cEnvType of line thisEnv of gCurrentEnv = "F" then
  261.         set newValue to item 3 of line thisEnv of gCurrentEnv
  262.         if newValue = "TRUE" then
  263.           set gFightMode to 1
  264.         end if
  265.         if newValue = "FALSE" then
  266.           set gFightMode to 0
  267.         end if
  268.       end if
  269.       if item cEnvType of line thisEnv of gCurrentEnv = "BS" then
  270.         set whichSound to item 3 of line thisEnv of gCurrentEnv
  271.         if whichSound = EMPTY then
  272.           if gMixSound then
  273.             puppetSound(0)
  274.             set gLastSound to EMPTY
  275.           else
  276.             puppetSound(0)
  277.             set gLastSound to EMPTY
  278.           end if
  279.           set gLastSound to whichSound
  280.         else
  281.           if gLastSound <> whichSound then
  282.             if gMixSound then
  283.               puppetSound(whichSound)
  284.               set gLastSound to whichSound
  285.             else
  286.               puppetSound(whichSound)
  287.               set gLastSound to EMPTY
  288.             end if
  289.           end if
  290.         end if
  291.       end if
  292.       if item cEnvType of line thisEnv of gCurrentEnv = "P" then
  293.         if the number of items in line thisEnv of gCurrentEnv = 3 then
  294.           set gPaletteList to item 3 of line thisEnv of gCurrentEnv
  295.         else
  296.           set gPaletteList to line thisEnv of gCurrentEnv
  297.           delete item 1 to 2 of gPaletteList
  298.         end if
  299.       end if
  300.       if item cEnvType of line thisEnv of gCurrentEnv = "BA" then
  301.         set gBrightAdjust to value(item 3 of line thisEnv of gCurrentEnv)
  302.       end if
  303.       if item cEnvType of line thisEnv of gCurrentEnv = "BC" then
  304.         set gBrightness to value(item 3 of line thisEnv of gCurrentEnv)
  305.       end if
  306.       if item cEnvType of line thisEnv of gCurrentEnv = "SP" then
  307.         set thisScript to value(item 3 of line thisEnv of gCurrentEnv)
  308.         do(thisScript)
  309.       end if
  310.       if item cEnvType of line thisEnv of gCurrentEnv = "DM" then
  311.         set gEnvDamage to item 3 to 8 of line thisEnv of gCurrentEnv
  312.       end if
  313.     end if
  314.   end repeat
  315. end
  316.  
  317. on ImportNewWorldCast
  318.   if the commandDown then
  319.     set fileObj to FileIO(mnew, "?read", "PICT")
  320.     if fileObj < 0 then
  321.       beep()
  322.     else
  323.       set saveCount to 0
  324.       set ImportPath to fileObj(mFileName)
  325.       put fileObj(mdispose)
  326.       set the itemDelimiter to ":"
  327.       set itemCount to the number of items in ImportPath
  328.       delete item itemCount of ImportPath
  329.       set the itemDelimiter to ","
  330.       put ":" after ImportPath
  331.       set lastCast to findEmptyCast()
  332.       repeat with count = 101 to lastCast - 1
  333.         duplicate(cast 10, cast count)
  334.       end repeat
  335.       set theFiles to []
  336.       set theFiles to GetFileList(ImportPath)
  337.       set fileCount to the number of lines in theFiles
  338.       repeat with count = 1 to fileCount
  339.         set saveCount to saveCount + 1
  340.         set thisFile to line count of theFiles
  341.         set thisFile to ImportPath & thisFile
  342.         importCast(thisFile)
  343.         if saveCount > 10 then
  344.           saveMovie()
  345.           set saveCount to 0
  346.         end if
  347.       end repeat
  348.       saveMovie()
  349.     end if
  350.   end if
  351. end
  352.  
  353. on GetRegions whichSite
  354.   global gClickRegionIndex, gClickRegions
  355.   set myRegions to EMPTY
  356.   set firstRegionIndex to value(getaProp(gClickRegionIndex, whichSite))
  357.   repeat with count = firstRegionIndex to the number of lines in gClickRegions
  358.     if item 1 of line count of gClickRegions = whichSite then
  359.       if item 1 of line count of gClickRegions = whichSite then
  360.         put line count of gClickRegions & RETURN after myRegions
  361.       end if
  362.       next repeat
  363.     end if
  364.     exit repeat
  365.   end repeat
  366.   if myRegions <> EMPTY then
  367.     delete line the number of lines in myRegions of myRegions
  368.   end if
  369.   return myRegions
  370. end
  371.  
  372. on GetEnviro whichSite
  373.   global gEnvStates, gEnvIndex
  374.   set myEnviroTable to EMPTY
  375.   set firstEnvIndex to value(getaProp(gEnvIndex, whichSite))
  376.   repeat with count = firstEnvIndex to the number of lines in gEnvStates
  377.     if item 1 of line count of gEnvStates = whichSite then
  378.       if item 1 of line count of gEnvStates = whichSite then
  379.         put line count of gEnvStates & RETURN after myEnviroTable
  380.       end if
  381.       next repeat
  382.     end if
  383.     exit repeat
  384.   end repeat
  385.   if myEnviroTable <> EMPTY then
  386.     delete line the number of lines in myEnviroTable of myEnviroTable
  387.   end if
  388.   return myEnviroTable
  389. end
  390.  
  391. on GetBaseSite whichSite
  392.   set done to 0
  393.   repeat while not done
  394.     set theCharCount to the number of chars in whichSite
  395.     if char theCharCount of whichSite >= "0" then
  396.       if char theCharCount of whichSite <= "9" then
  397.         set whichSite to char 1 to theCharCount - 1 of whichSite
  398.         next repeat
  399.       end if
  400.       set done to 1
  401.     end if
  402.   end repeat
  403.   return whichSite
  404. end
  405.  
  406. on ClearPanSites
  407.   global gPanRegions, cMaxRegions, cSiteFirstRegion, cPanFirstRegion
  408.   set cView.Left to 0
  409.   set cView.Top to 0
  410.   set cView.Right to 640
  411.   set cView.Bottom to 390
  412.   spriteBox(cPanView, cView.Left + cView.Right + 1, cView.Top, cView.Right + cView.Right + 1, cView.Bottom)
  413.   set cView.Left to 0
  414.   set cView.Top to 0
  415.   set cView.Right to 640
  416.   set cView.Bottom to 390
  417.   spriteBox(cCurrentView, cView.Left, cView.Top, cView.Right, cView.Bottom)
  418.   repeat with count = 1 to cMaxRegions
  419.     set thisSprite to count + cPanFirstRegion - 1
  420.     puppetSprite(thisSprite, 1)
  421.     spriteBox(thisSprite, 0, 500, 1, 501)
  422.   end repeat
  423. end
  424.  
  425. on CheckAltSites whichSite
  426.   global gCurrentSite, gStateTable, gStateTableIndex
  427.   set me to whichSite
  428.   set whichSite to GetBaseSite(whichSite)
  429.   set firstObjIndex to value(getaProp(gStateTableIndex, whichSite))
  430.   set myObjTable to EMPTY
  431.   repeat with count = firstObjIndex to the number of lines in gStateTable
  432.     if item 1 of line count of gStateTable = whichSite then
  433.       if item 1 of line count of gStateTable = whichSite then
  434.         put line count of gStateTable & RETURN after myObjTable
  435.       end if
  436.       next repeat
  437.     end if
  438.     exit repeat
  439.   end repeat
  440.   if myObjTable <> EMPTY then
  441.     delete line the number of lines in myObjTable of myObjTable
  442.   else
  443.     set gCurrentSite to me
  444.     return me
  445.     exit
  446.   end if
  447.   set StateCount to the number of lines in myObjTable
  448.   repeat with thisItem = 1 to StateCount
  449.     if item 1 of line thisItem of myObjTable = whichSite then
  450.       set SiteStateCount to item 3 of line thisItem of myObjTable
  451.       set theResult to 0
  452.       repeat with thisState = 1 to SiteStateCount
  453.         set whichObj to item (2 * (thisState - 1)) + 4 of line thisItem of myObjTable
  454.         set whichCond to item (2 * (thisState - 1)) + 5 of line thisItem of myObjTable
  455.         set theResult to value(TestObjStates(whichObj, whichCond)) + theResult
  456.       end repeat
  457.       if theResult = SiteStateCount then
  458.         set me to item 2 of line thisItem of myObjTable
  459.         set thisItem to 100
  460.       end if
  461.     end if
  462.   end repeat
  463.   set gCurrentSite to me
  464.   return me
  465. end
  466.  
  467. on StoreCleanUpSpriteUsage
  468.   global cMaxRegions, cPanFirstRegion, cArmSprite, cArmSpriteMax
  469.   put the freeBytes
  470.   repeat with thisSprite = cPanFirstRegion to cPanFirstRegion + cMaxRegions - 1
  471.     set killCastNum to the castNum of sprite thisSprite
  472.     unLoadCast(killCastNum)
  473.   end repeat
  474.   repeat with thisSprite = cArmSprite to cArmSprite + cArmSpriteMax
  475.     set killCastNum to the castNum of sprite thisSprite
  476.     unLoadCast(killCastNum)
  477.   end repeat
  478.   put the freeBytes
  479. end
  480.  
  481. on slideSprite snum, endH, endV
  482.   set pixelJump to 5.0
  483.   set maxSteps to 15
  484.   set startH to the locH of sprite snum
  485.   set startV to the locV of sprite snum
  486.   set deltaH to endH - startH
  487.   set deltaV to endV - startV
  488.   if abs(deltaH) > abs(deltaV) then
  489.     set steps to float(abs(deltaH) / pixelJump)
  490.   else
  491.     set steps to float(abs(deltaV) / pixelJump)
  492.   end if
  493.   if steps > maxSteps then
  494.     set steps to maxSteps
  495.   end if
  496.   if abs(steps) > 1 then
  497.     set addH to float(deltaH / steps)
  498.     set addV to float(deltaV / steps)
  499.     repeat with stepCount = 1 to steps
  500.       set the locH of sprite snum to startH + (stepCount * addH)
  501.       set the locV of sprite snum to startV + (stepCount * addV)
  502.       updateStage()
  503.     end repeat
  504.   end if
  505.   set the locH of sprite snum to endH
  506.   set the locV of sprite snum to endV
  507.   updateStage()
  508. end
  509.